package common.matchAward.item
{
	import com.common.utils.DisplayObjectUtil;
	import com.greensock.TweenLite;
	import com.liangzhong.model.AppData;
	import com.liangzhong.model.goods.vo.GoodsVo;
	import com.liangzhong.model.playerCenter.vo.PlayerVo;
	import com.lz.football.module.base.IComponent;
	
	import common.item.ComGoodsItem;
	import common.item.IconItem;
	import common.item.LPlayerItem;
	import common.item.LPropItem;
	
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	
	import lz.controls.LItem;

	/**
	 *奖励item 
	 * @author lake
	 * 
	 */	
	public class MatchAwardItem extends LItem implements IComponent
	{
		/**
		 * 原始x，y 
		 */		
		private var orX :Number = 0;
		private var orY :Number = 0;
		/**
		 *选中状态 
		 */		
		private var selectMc :MovieClip;
		/**
		 *道具名字 
		 */		
		private var propName :String ;
		
		public function MatchAwardItem()
		{
			super();
		}
		/**
		 *设置数据 
		 * @param value
		 * 
		 */		
		override public function set data(value:*):void
		{
			super.data = value;
			if(_symbolSkin == null)
			{
				return;
			}
			_symbolSkin.play();
			var iconItem :DisplayObject = getItem();
			DisplayObjectUtil.removeAllChildren(_symbolSkin.iconContainer);
			_symbolSkin.iconContainer.addChild(iconItem);
			iconItem.x = -2;
			iconItem.y = -1;
			_symbolSkin.cardMc.txtName.htmlText = "" + propName;
		}
		/**
		 *获取item 
		 * @return 
		 * 
		 */		
		private function getItem():DisplayObject
		{
			propName = "";
			var pid :int = _data.id;
			var type :int = _data.type;
			var goodsVo :GoodsVo = AppData.getInstance().goodsManager.getGoodsByTypeAndId(type,pid);
			var iconItem :ComGoodsItem;
			iconItem = new ComGoodsItem();
			iconItem.initUI();
			iconItem.data = goodsVo;
			propName = goodsVo.name;
			return iconItem;
		}
		/**
		 *初始化 
		 * @param view
		 * 
		 */		
		public function initUI(view:Object=null):void
		{
			_symbolSkin = view as MovieClip;
			if(_symbolSkin == null)
			{
				return;
			}
			_symbolSkin.buttonMode = false;
			orX = _symbolSkin.x;
			orY = _symbolSkin.y;
			selectMc = _symbolSkin.selectMc;
			_symbolSkin.gotoAndStop(25);
			if(selectMc)
			{
				selectMc.visible = false;
			}
			addEvtListener();
		}
		/**
		 *复制奖励item 
		 * @return 
		 * 
		 */		
		public function cloneItem():DisplayObject
		{
			return getItem();
		}
		/**
		 *添加事件 
		 * 
		 */		
		public function addEvtListener():void
		{
			_symbolSkin.addEventListener(MouseEvent.ROLL_OVER,rollOverHandler);
			_symbolSkin.addEventListener(MouseEvent.ROLL_OUT,rollOutHandler);
			_symbolSkin.addEventListener(MouseEvent.CLICK,clickHandler);
		}
		/**
		 *移上 
		 * @param e
		 * 
		 */		
		private function rollOverHandler(e :MouseEvent):void
		{
			var toX :Number = _symbolSkin.x - 8;
			var toY :Number = _symbolSkin.y - 13;
			//TweenLite.to(_symbolSkin,.3,{scaleX:1.2,scaleY:1.2,x:toX,y:toY});
		}
		/**
		 *移开 
		 * @param e
		 * 
		 */		
		private function rollOutHandler(e :MouseEvent = null):void
		{
			//TweenLite.to(_symbolSkin,.3,{scaleX:1,scaleY:1,x:orX,y:orY});
		}
		/**
		 *点击 
		 * @param e
		 * 
		 */		
		private function clickHandler(e :MouseEvent):void
		{
			rollOutHandler();
			removeEvtListener();
			_symbolSkin.dispatchEvent(new MouseEvent(MouseEvent.CLICK));
			if(selectMc)
			{
				selectMc.visible = true;
			}
		}
		/**
		 *选择 
		 * 
		 */		
		override public function select():void
		{
			if(selectMc)
			{
				selectMc.visible = true;
			}
		}
		/**
		 *删除事件 
		 * 
		 */		
		public function removeEvtListener():void
		{
			_symbolSkin.removeEventListener(MouseEvent.ROLL_OVER,rollOverHandler);
			_symbolSkin.removeEventListener(MouseEvent.ROLL_OUT,rollOutHandler);
			_symbolSkin.removeEventListener(MouseEvent.CLICK,clickHandler);
			_symbolSkin.buttonMode = false;
		}
		/**
		 *销毁 
		 */		
		public function destroyView():void
		{
			removeEvtListener();
			_data = null;
		}
	}
}